﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

namespace BOA.HelpDesk
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();


            ScheduleTimer schedule = new ScheduleTimer();
            schedule.RegisterAndStart();

        }
    }



    public class ScheduleTimer
    {
        public void RegisterAndStart()
        {

            System.Timers.Timer timer = new System.Timers.Timer();
            //timer.Interval =  5000;  //5 segundos = 5000
            timer.Interval = 60000;
            timer.Elapsed += MiAyudante;
            timer.Start();

            //Application.Add("timer", timer);
        }

        void MiAyudante(object sender, System.Timers.ElapsedEventArgs e)
        {
            Object thisLock = new Object();

            lock (this)
            {
                var data = Boa.HD.AccesoDatos.Contratos.DataFactory.Current.GetSubePrioridadData();
                string AltaMuyAlta = System.Configuration.ConfigurationManager.AppSettings["ActualizarAltaAMuyAlta"];
                string MediaAlta = System.Configuration.ConfigurationManager.AppSettings["ActualizarMediaAAlta"];
                string BajaMedia = System.Configuration.ConfigurationManager.AppSettings["ActualizarBajaAMedia"];
                data.SubirPrioridad(Convert.ToInt32(AltaMuyAlta), Convert.ToInt32(MediaAlta), Convert.ToInt32(BajaMedia));

            }
        }
    
    }

}